import React, { useState } from 'react';
import './App.css';

// function App() {
//   const [count, setCount] = useState(0);

//   return (
//     <div className="App">
//       <h1>count: {count}</h1>
//       <button type="button" onClick={() => {
//         setCount(() => count + 1, () => {
//           console.log(count)  // 函数组件中，useState()返回的setCount方法，没有参数2.
//         })
//       }}>increment</button>
//     </div>
//   );
// }
class App extends React.Component {
  state = {
    count: 0
  }
  render() {
    return (
      <div className="App">
        <h1>count: {this.state.count}</h1>
        <button type="button" onClick={() => {
          this.setState(
            () => {
              return { count: this.state.count + 1 };
            },
            () => { console.log(this.state.count) })
        }}>increment</button>
      </div>
    )
  }
}

export default App;
